package user

import (
	"API/client"
	"API/request"
	"context"
	"github.com/gin-gonic/gin"
	user "user_server/proto"
)

func GetUserDetail(c *gin.Context) {
	var req request.UserDetailRequest
	if err := c.ShouldBindQuery(&req); err != nil {
		c.JSON(400, gin.H{
			"code": 400,
			"msg":  "请求参数错误",
		})
		return
	}

	// 调用用户服务
	userId := c.GetUint("userId")
	res, err := client.GetUserDetail(context.Background(), &user.UserDetailRequest{
		UserId: int32(userId),
	})
	if err != nil {
		c.JSON(500, gin.H{
			"code": 500,
			"msg":  "获取用户详情失败",
		})
		return
	}

	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "success",
		"data": gin.H{
			"user_id":              res.UserId,
			"nickname":             res.Nickname,
			"tel":                  res.Tel,
			"avatar":               res.Avatar,
			"real_name":            res.RealName,
			"is_verified":          res.IsVerified,
			"created_at":           res.CreatedAt,
			"continuous_sign_days": res.ContinuousSignDays,
			"retroactive_cards":    res.RetroactiveCards,
			"last_sign_date":       res.LastSignDate,
		},
	})
}
